//
//  DenglumimaVC.m
//  SSC
//
//  Created by 红沙尘 on 17/6/10.
//  Copyright © 2017年 红沙尘. All rights reserved.
//

#import "DenglumimaVC.h"
#import "AppDelegate.h"

@interface DenglumimaVC ()
{
    __weak IBOutlet UIButton *sureBtn;
}

@end

@implementation DenglumimaVC

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setTitle:@"修改登录密码"];
}

- (IBAction)sure:(id)sender {
    
    if (![MTool judgePassWordLegal:newFieldA.text]) {
        [MTool showAlertController:self message:@"密码为6-16个数字与字母的组合"];
        
        return;
    }
    
    if (![MTool judgePassWordLegal:newFieldB.text]) {
        [MTool showAlertController:self message:@"密码为6-16个数字与字母的组合"];
        
        return;
    }
    
    [self sendRequest];
}

- (void)sendRequest {
    
    [LoadingView show];
    
    [SSCRequest updatepassword:oldField.text
                      password:newFieldA.text
                  truepassword:newFieldB.text
                       success:^(NSDictionary *responseObject)
     {
         [LoadingView diss];
         WeakSelf;
         [weakSelf showAlert];
     } fail:^(NSError *error) {
         [LoadingView diss];
     }];
}

- (void)showAlert {
    
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@""
                                                                             message:@"修改密码成功,请重新登录"
                                                                      preferredStyle:UIAlertControllerStyleAlert];
    
    [alertController addAction:[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
        AppDelegate *app = (AppDelegate *)[UIApplication sharedApplication].delegate;
        [app gotoLogin];
    }]];
    [self presentViewController:alertController animated:YES completion:nil];
}

- (void)setupUI {
    sureBtn.layer.cornerRadius  = 2;
    sureBtn.layer.masksToBounds = YES;
}



@end















